package com.banana.scheduler;

import java.io.File;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import java.util.Properties;
import java.util.Scanner;


public class FileJobScanner implements JobScanner{

	private final File seedFile;
	private List<SimpleJob> jobList = new LinkedList<SimpleJob>();
	private long givenInterval = 0;
	private Scanner jobScanner ;
	
	public FileJobScanner(Properties prop) throws Exception { 
		this.seedFile = new File(prop.getProperty("FileJobScanner.seedFile"));
		this.givenInterval = new Long(prop.getProperty("FileJobScanner.givenInterval"));
	}

	
	@Override
	public synchronized List<SimpleJob> scan() throws Exception {
		// TODO Auto-generated method stub
		jobScanner = new Scanner(seedFile);
		while (jobScanner.hasNext()) { 
			String item = jobScanner.next();
			String [] token = item.split("=");
			jobList.add(new SimpleJob(token[0],new URL(token[1]),this.givenInterval));
		}
//		SimpleJob simpleJob = (SimpleJob) seedList.get(index);
//		index++;
//		if (index == seedList.size()) { 
//			index=0;
//		}
		
		return jobList; 
	}
	
}
